<html>
<head><meta charset="utf-8"><title>structural equality · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html">structural equality</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238686037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238686037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238686037">(May 13 2021 at 21:47)</a>:</h4>
<p>So in <a href="https://github.com/rust-lang/rust/issues/84045">#84045</a> <a href="https://github.com/rust-lang/rust/pull/84045#issuecomment-839850571">we were discussing</a> the idea of having a pow-wow to talk over structural equality (cc <span class="user-mention" data-user-id="120791">@RalfJ</span>, <span class="user-mention" data-user-id="124288">@oli</span>, <span class="user-mention" data-user-id="216206">@lcnr</span>, <span class="user-mention" data-user-id="121053">@varkor</span>), maybe we could use a const generics meeting to push on that? e.g. next week at <time datetime="2021-05-18T14:45:00Z">2021-05-18T10:45:00-04:00</time> ?</p>



<a name="238686091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238686091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238686091">(May 13 2021 at 21:47)</a>:</h4>
<p>I'm not sure who else to cc :)</p>



<a name="238697342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238697342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238697342">(May 13 2021 at 23:42)</a>:</h4>
<p><span class="user-group-mention" data-user-group-id="1916">@WG-const-eval</span></p>



<a name="238759346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238759346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238759346">(May 14 2021 at 12:35)</a>:</h4>
<p>Would that be a good time to raise <a href="https://github.com/rust-lang/rust/issues/84391">https://github.com/rust-lang/rust/issues/84391</a>, and the more general point (which is a concern of mine) of <code>derive(Eq,PartialEq)</code> being observably different from an equivalent manual implementation?</p>



<a name="238762649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238762649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238762649">(May 14 2021 at 13:02)</a>:</h4>
<p>oof. that's unfortunate and a really good datapoint for finding a less magical scheme for allowing types in const generics. We should def make it a discussion point of that meeting</p>



<a name="238765157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238765157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238765157">(May 14 2021 at 13:21)</a>:</h4>
<p>C++ may have had similar issues raised when debating CNTTP for C++20, as <a href="https://wg21.link/p0732">p0732</a> defines it in terms of types with <em>strong structural equality</em> (which is effectively equivalent to <code>derive(Eq,PartialEq)</code>), but C++20 uses a different <em>structural</em> definition <a href="http://eel.is/c++draft/temp.param#7">http://eel.is/c++draft/temp.param#7</a>, which requires that class types have only public <em>strutural</em> members (and makes no reference to <code>operator&lt;=&gt;</code> at all). This may be an alternative to consider for const generics as well.</p>



<a name="238772010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772010">(May 14 2021 at 14:05)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> thnks for raising that. I think your point, if i may restate, is that we have never audited the various PartialEq/Eq impls to be sure that we really intended them to be "structural eq" -- in other words, structural equality may be a different property that shouldn't be just tied to PartialEq vs Eq?</p>



<a name="238772031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772031">(May 14 2021 at 14:05)</a>:</h4>
<p>Also, can you elaborate a bit more on why you see it as a problem to have TypeId as a const</p>



<a name="238772163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772163">(May 14 2021 at 14:06)</a>:</h4>
<p>i feel like you are saying that this makes it imposible to make changes the type-id hashing algorithm</p>



<a name="238772178"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772178" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772178">(May 14 2021 at 14:06)</a>:</h4>
<p>(Also, <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span> so happy you are working on that! <span aria-label="pray" class="emoji emoji-1f64f" role="img" title="pray">:pray:</span> )</p>



<a name="238772209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772209">(May 14 2021 at 14:07)</a>:</h4>
<p><span class="user-mention" data-user-id="257758">@Connor Horman</span> speaking of that, can I add that to the lang team project board as an active project?</p>



<a name="238772814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238772814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238772814">(May 14 2021 at 14:10)</a>:</h4>
<p>Sure. So the issue generally is more of an implementation issue, where the currently (imo, over) use of <code>derive(PartialEq,Eq)</code> in the standard library may have consequences for implementations down the road (especially with const generics). I ran into this while implementing TypeId for <a href="https://github.com/LightningCreations/lccc">lccc</a>'s standard library, which included an implementation suggested by a user of the Rust Community Discord that solved <a href="https://github.com/rust-lang/issues/10389">#10389</a>, but can't use <code>derive(PartialEq)</code> or <code>derive(Eq)</code>.</p>



<a name="238773442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238773442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238773442">(May 14 2021 at 14:15)</a>:</h4>
<p>The issue with TypeId is that any sort of structural implementation of TypeId will have a (potentially non-sigificant) chance of running into any collisions (without the mechanisms necessary to apply a perfect hash function, which would likely be impossible with <code>dylib</code>s), thus making TypeId fundamentally unsound, depending on who you ask (and different implementors may make different decisions on what chance makes it statistically significant). It would not specifically lock everything to the current implementation, it would simply reduce the amount of freedom to avoid collisions.</p>



<a name="238773535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238773535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238773535">(May 14 2021 at 14:15)</a>:</h4>
<p>I started a doc for the meeting: <a href="https://hackmd.io/VxadMjxdRfiObV2FR03vWQ">https://hackmd.io/VxadMjxdRfiObV2FR03vWQ</a></p>



<a name="238774053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238774053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238774053">(May 14 2021 at 14:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238772209">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> speaking of that, can I add that to the lang team project board as an active project?</p>
</blockquote>
<p>Possibly. I'm currently waiting on discussion T-libs before starting any of the work (since it's mostly in their domain). I brought it up because the issue is relevant to const-generics (See the note that the <code>derive(PartialEq,Eq)</code> can be observed with <code>#![feature(const_generics)]</code>).</p>



<a name="238811170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238811170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238811170">(May 14 2021 at 18:39)</a>:</h4>
<p>For floating point values, it is worth noting the <code>total_cmp</code> operation we have introduced on nightly, which is specified as well-defined by IEEE754-2008, and provides a total order on binary floating point.</p>



<a name="238811567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238811567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238811567">(May 14 2021 at 18:42)</a>:</h4>
<p>while that works very well for matching, const generics will have to generate a symbol name that is 100% equal to any "equal" (whatever that means) value. So the same NaN used in a const generic... should be the same symbol? Or should different NaNs be different symbols? Idk, I don't have a good answer here</p>



<a name="238812624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238812624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238812624">(May 14 2021 at 18:51)</a>:</h4>
<p>It may be a good idea to look into how C++20 handles NaNs in NTTPs, as <code>float</code>s were added.<br>
According to &lt;<a href="http://eel.is/c++draft/temp.type#2.2">http://eel.is/c++draft/temp.type#2.2</a>&gt;, two float values are <em>template-argument-equivalent</em> if they are identical (note: Not equal), but I haven't found a definition for that, nor anything that suggests NaNs are disallowed. It's possible that <code>NaN</code>s consider bitwise equality in floats.</p>



<a name="238812719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238812719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238812719">(May 14 2021 at 18:52)</a>:</h4>
<p>Yeah, in actual practice, we don't want to really allow much in terms of meaningful const-time introspection on NaN values due to certain codegen backends having very creative interpretations. ^^;</p>



<a name="238814356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238814356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238814356">(May 14 2021 at 19:04)</a>:</h4>
<p>It seems like gcc, for C++, mangles the float values bitwise, <a href="https://godbolt.org/z/fcT1P3fd3">https://godbolt.org/z/fcT1P3fd3</a>, so that's a potential route for rust implementations to take (and thus would permit NaNs in cg)</p>



<a name="238816885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238816885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238816885">(May 14 2021 at 19:24)</a>:</h4>
<p>I can list the parts of NaN values that can be determined without an oracle.<br>
An oracle, for these purposes, is either directly introspecting the bits, or any suitable side channel that provides similar knowledge of how the FPE (Floating Point Environment) happens to work, like having a table to look at for how the compilation target handles generating NaNs, or injecting an op that would make the value decidable without affecting overall program execution.</p>
<p>The first is whether it is a qNaN or an sNaN. This is actually pretty knowable at all times, as it is fairly deterministic and target-independent, as far as the standard understands it.<br>
The second is whether it is a positive or negative NaN. This is harder to know. A NaN always has a positive or negative sign, but there are several conditions where it is valid for the FPE to assign either to the NaN, so you must consult an oracle.</p>
<p>However, LLVM and WASM both have... interesting attitudes towards the standard. The LLVM and WASM FPE consider it valid to substitute NaNs they encounter with their "canon NaNs", which for LLVM are NaNs with the bit value 0x3F800000 and 0x3FF0000000000000, and I think might be the same for WASM.</p>



<a name="238816978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238816978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238816978">(May 14 2021 at 19:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> what's a "pow-wow"?^^</p>



<a name="238817287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817287">(May 14 2021 at 19:28)</a>:</h4>
<p>Indeed, and for the purposes of cg, it's entirely possible that there are only two NaNs: one quiet and one signaling. AFAIK there aren't any limitations on the bitpatterns produced by particular floating-point operations yielding NaN.</p>



<a name="238817436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817436">(May 14 2021 at 19:29)</a>:</h4>
<p>I would prefer not to handle NaN at all, we can easily detect them and just error if you try to put them into a const generic</p>



<a name="238817640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817640">(May 14 2021 at 19:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238762649">said</a>:</p>
<blockquote>
<p>oof. that's unfortunate and a really good datapoint for finding a less magical scheme for allowing types in const generics. We should def make it a discussion point of that meeting</p>
</blockquote>
<p>also see <a href="https://github.com/rust-lang/rust/issues/74446">https://github.com/rust-lang/rust/issues/74446</a> and the last section of <a href="https://hackmd.io/Qvrj_eOFTkCHZrhJ7f1ItA">https://hackmd.io/Qvrj_eOFTkCHZrhJ7f1ItA</a> -- I think <code>StrucuralEq</code> as a concept makes sense but we need to fundamentally change its definition</p>



<a name="238817657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817657">(May 14 2021 at 19:31)</a>:</h4>
<p>or rather, we need to come up with a proper definition in the first place :D</p>



<a name="238817780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817780">(May 14 2021 at 19:32)</a>:</h4>
<p>If you do certain operations on a NaN value that set its sign value, like <code>abs</code> or <code>copysign</code>, it <em>should</em> acquire that sign value.<br>
And indeed. I figured I'd enumerate the situation with NaNs, but far as I am concerned actually handling NaN during CTFE basically only makes sense by handling NaN as one entity, the abstract set containing all possible NaN values.</p>



<a name="238817937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817937">(May 14 2021 at 19:33)</a>:</h4>
<p>I also think floats are a sufficiently special case that we should figure out the high-level direction first before going into so much detail</p>



<a name="238817952"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238817952" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238817952">(May 14 2021 at 19:33)</a>:</h4>
<p>That's Completely Fair.</p>



<a name="238819900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238819900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238819900">(May 14 2021 at 19:48)</a>:</h4>
<p>Here's a question: what is Structural Equality supposed to <strong>enable</strong>?<br>
I get that it has a shaky definition, but I figure that it has a clear <strong>aim</strong>. Yet I have tried to read a bunch of these documents but I still don't know. <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="238821044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238821044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238821044">(May 14 2021 at 19:56)</a>:</h4>
<p>Or perhaps I should say: at first I thought it was just for addressing certain soundness criteria for <code>match</code>, but then I read all this stuff, and now I know I know nothing.</p>



<a name="238868865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238868865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238868865">(May 15 2021 at 04:56)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> A “pow wow” is American slang for a meeting. <a href="https://en.wikipedia.org/wiki/Pow_wow">https://en.wikipedia.org/wiki/Pow_wow</a></p>



<a name="238876827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238876827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238876827">(May 15 2021 at 07:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238686037">said</a>:</p>
<blockquote>
<p>So in <a href="https://github.com/rust-lang/rust/issues/84045">#84045</a> <a href="https://github.com/rust-lang/rust/pull/84045#issuecomment-839850571">we were discussing</a> the idea of having a pow-wow to talk over structural equality (cc <span class="user-mention silent" data-user-id="120791">RalfJ</span>, <span class="user-mention silent" data-user-id="124288">oli</span>, <span class="user-mention silent" data-user-id="216206">lcnr</span>, <span class="user-mention silent" data-user-id="121053">varkor</span>), maybe we could use a const generics meeting to push on that? e.g. next week at <time datetime="2021-05-18T14:45:00Z">2021-05-18T10:45:00-04:00</time> ?</p>
</blockquote>
<p>sure, yeah</p>



<a name="238885218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238885218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238885218">(May 15 2021 at 09:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219696">XAMPPRocky</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238868865">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> A “pow wow” is American slang for a meeting. <a href="https://en.wikipedia.org/wiki/Pow_wow">https://en.wikipedia.org/wiki/Pow_wow</a></p>
</blockquote>
<p>TIL, thanks :)</p>



<a name="238885238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238885238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238885238">(May 15 2021 at 09:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281757">Jubilee</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238819900">said</a>:</p>
<blockquote>
<p>Here's a question: what is Structural Equality supposed to <strong>enable</strong>?<br>
I get that it has a shaky definition, but I figure that it has a clear <strong>aim</strong>. Yet I have tried to read a bunch of these documents but I still don't know. <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>
</blockquote>
<p>yes indeed I think this is the question we should start with. :)</p>



<a name="238885264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238885264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238885264">(May 15 2021 at 09:56)</a>:</h4>
<p>It is tied up with both <code>match</code> and const generics</p>



<a name="238886560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238886560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238886560">(May 15 2021 at 10:18)</a>:</h4>
<p>My personal thinking (which is some variant of the links I posted <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238817640">above</a>) is roughly as follows:<br>
In general, the value of a constant (<code>const</code>/<code>static</code> body, but also more general any <code>Constant</code> MIR operand, which includes all literals)  inside rustc is just an unstructured blob of bytes (and <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/struct.Allocation.html"><code>Allocation</code></a>, in technical terms). This is sufficient for when a <code>const</code> is just used in code. (There's a slight inaccuracy here in that, for efficiency reasons, we do not actually create an <code>Allocation</code> for each integer literal, so we have more efficient representations for some very simple constants. This is not relevant for the <code>StructuralEq</code> discussion.)<br>
However, there are 2 things the compiler does where an "unstructured blob" view of a constant is insufficient:</p>
<ul>
<li>pattern matching against a <code>const</code>, if we want exhaustiveness checking to properly take the <code>const</code> into account (i.e., "as-if" the <code>const</code> would have been written inline as a normal pattern). Note that if we <em>don't</em> do exhaustiveness checking then we can still treat the <code>const</code> as a blob; this is sound if exhaustiveness checking considers such a match arm to not match <em>anything</em>, thus enforcing the addition of a fallback <code>_</code> arm. In this case the <code>match</code> can be implemented by calling <code>PartialEq</code>.</li>
<li>const generics. In particular here we need a notion of equality on consts that acts more like <code>PartialEq</code> than <code>memcmp</code>, i.e., comparing references by comparing their pointees and skipping padding bytes.</li>
</ul>
<p>Not all consts of all types can be treated in this more structured way, so this is where the need of a <code>StructuralEq</code> constraint arises.</p>
<p>To support these usecases, the compiler will use "valtrees",  a high-level, more structural representation of a constant. A valtree is a tree where the leaves carry integer values and both pointer indirection and "is a field of" are represented as edges between nodes.<br>
So e.g. <code>2</code> would be a valtree with just a single node carrying a 2; <code>(2, 2)</code> would be a valtree where the root points to two leaf nodes that carry a 2. <code>&amp;2</code> would be a valtree where the root points to a leaf node that carries a 2. <code>(2,)</code> would be the same valtree as <code>&amp;2</code>; that's okay -- valtrees are meant to capture everything about a value that matters at a high level; comparing valtrees of different types is not very meaningful.</p>
<p>Pattern matching exhaustiveness checking can use valtrees to basically convert a constant into a regular pattern and then treat it as-if that pattern had been written literally. Const generics can compare two valtrees (where inner nodes are compared by recursively comparing the children) to determine equality of const values.</p>
<p>Now, which values are safe to be converted into valtees? I think this is the class of values that we want to say has "structural equality", and then we can say that <code>T: StructuralEq</code> if <em>all</em> values of <code>T</code> have "structural equality". (Note that e.g. the value <code>None::&lt;T&gt;</code> has structural equality for all <code>T</code>, that's why it makes sense to distinguish value-level and type-level notions here. I am not suggesting we actually do anything like this in rustc, but I think it is good to develop the theory in this style. And if we want to allow non-NAN floats in const generics, we <em>do</em> have to take this approach.)<br>
There are some values which we simply cannot turn into valtrees, so they are out, most notably all values of union type (because a union is just a bag of bytes, there's no high-level representation we can turn that into). But we also quickly realize that there is a deep link with equality here: the behavior of pattern matching against a constant should ideally be equivalent to testing equality with <code>PartialEq</code>. And likewise for const generics, when two constants are equal according to <code>PartialEq</code>, we better treat them as "equal" from the perspective of the type system. This guides us to the following key constraint that I think must be satisifed to ensure things make sense:</p>
<p>STRUCT1: <em>Given two values <code>v1</code>, <code>v2</code> of type <code>T: PartialEq</code>, if both can be converted to a valtree then the valtrees are equal if and only if <code>v1 == v2</code>. Moreover, if <code>v1</code> can be converted to a valtree and <code>v2</code> cannot, then <code>!(v1 == v2)</code>.</em></p>
<p>(Remember that "can be converted to a valtree" is equivalent to "has structural equality".)</p>
<p>This is the basic minimum. I feel like we might want to strengthen this to make it easier to reason about; making definitions conditional on whether a type implements a trait is tricky business (if we aren't careful, adding a <code>PartialEq</code> impl can now break this property! We saw with <code>Pin</code> how easily this goes wrong). Also <code>PartialEq</code> allows some "whacky" non-reflexive equality relations which don't make these things easier to think about. So I think we want a property more like:</p>
<p>STRUCT2: <em>When a value <code>v1</code> of type <code>T</code> can be converted to a valtree, then <code>T: Eq</code> and for any <code>v2: T</code>, their valtrees are equal if and only if <code>v1 == v2</code> (in particular if <code>v2</code> cannot be converted into a valtree, then <code>!(v1 == v2)</code>).</em></p>
<p>As above, a type <code>T</code> is <code>StrucuralEq</code> if all its values can be converted to a valtree. This lends itself toward saying that the trait should be declared as</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">/// SAFETY constraint: all values of this type must be convertible to valtrees such</span>
<span class="sd">/// that the valtrees are equal if and only if the values compare equal with `Eq::eq`.</span>
<span class="k">unsafe</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">StructuralEq</span>: <span class="nb">Eq</span> <span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="238887042"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887042" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887042">(May 15 2021 at 10:27)</a>:</h4>
<p>(However, I am not entirely sure if this is fully backwards compatible -- we currently allow constants in pattern matching that are <em>not</em> <code>StructuralEq</code> under this definition, and I don't know if we do exhaustiveness checking for them.)</p>



<a name="238887093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887093">(May 15 2021 at 10:28)</a>:</h4>
<p>back compat strikes again <span aria-label="pensive" class="emoji emoji-1f614" role="img" title="pensive">:pensive:</span></p>



<a name="238887137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887137">(May 15 2021 at 10:29)</a>:</h4>
<p>It always does.^^</p>



<a name="238887155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887155">(May 15 2021 at 10:29)</a>:</h4>
<p>(Editing the text slightly, I realized after looking at <a href="https://github.com/rust-lang/rust/issues/74446">https://github.com/rust-lang/rust/issues/74446</a> that we probably want something slightly stronger. -- Done)</p>



<a name="238887570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887570">(May 15 2021 at 10:35)</a>:</h4>
<p>Note that the requirement of <code>StructuralEq</code> as given above implies that <code>Eq</code> actually is a proper equivalence relation, assuming that the equality on valtrees is (which I am pretty sure we want^^). So that would be another argument for why talking about <code>PartialEq</code> makes little sense.</p>



<a name="238887729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887729">(May 15 2021 at 10:37)</a>:</h4>
<p>That said, for <em>per-value</em> structural equality, <code>1.0f32</code> could have structural equality, just <code>NAN</code> couldn't -- so STRUCT2 could reasonably be weakened to <code>PartialEq</code>.</p>



<a name="238887849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887849">(May 15 2021 at 10:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="326176">Boxy [she/her]</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238887093">said</a>:</p>
<blockquote>
<p>back compat strikes again <span aria-label="pensive" class="emoji emoji-1f614" role="img" title="pensive">:pensive:</span></p>
</blockquote>
<p>I think we'll be fine though... assuming floats and (raw and fn) pointers always require a <code>_</code> arm</p>



<a name="238887894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/238887894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#238887894">(May 15 2021 at 10:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238686037">said</a>:</p>
<blockquote>
<p>So in <a href="https://github.com/rust-lang/rust/issues/84045">#84045</a> <a href="https://github.com/rust-lang/rust/pull/84045#issuecomment-839850571">we were discussing</a> the idea of having a pow-wow to talk over structural equality (cc <span class="user-mention silent" data-user-id="120791">RalfJ</span>, <span class="user-mention silent" data-user-id="124288">oli</span>, <span class="user-mention silent" data-user-id="216206">lcnr</span>, <span class="user-mention silent" data-user-id="121053">varkor</span>), maybe we could use a const generics meeting to push on that? e.g. next week at <time datetime="2021-05-18T14:45:00Z">2021-05-18T10:45:00-04:00</time> ?</p>
</blockquote>
<p>yes that time works for me</p>



<a name="239258957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239258957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239258957">(May 18 2021 at 14:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> is there a link for where the meeting will happen?</p>



<a name="239259258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239259258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239259258">(May 18 2021 at 14:06)</a>:</h4>
<p>I assume here on zulip, but if not, I would also like to know that.</p>



<a name="239259351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239259351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239259351">(May 18 2021 at 14:06)</a>:</h4>
<p>oh I thought it'd be a live call (for higher bandwidth)</p>



<a name="239262214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239262214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239262214">(May 18 2021 at 14:25)</a>:</h4>
<p>so, we have <a href="https://github.com/rust-lang/rust/issues/74446">#74446</a>, especially <a href="https://github.com/rust-lang/rust/issues/74446#issuecomment-841637790">ralfs summary</a></p>



<a name="239263314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239263314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239263314">(May 18 2021 at 14:31)</a>:</h4>
<p>there's <a href="https://github.com/rust-lang/rust/issues/84391">#84391</a> which brings up some concerns with implicitly making stuff structural match. The concern seems to be that going from a derived <code>PartialEq</code> to a manual one is breaking if it there is a way to get a constant of that type.</p>



<a name="239263479"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239263479" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239263479">(May 18 2021 at 14:32)</a>:</h4>
<p>there's <a href="https://github.com/rust-lang/project-const-generics/issues/6">project-const-generics#6</a>, which is about the same issue but only focussed on allowing types as const param types</p>



<a name="239264217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239264217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239264217">(May 18 2021 at 14:36)</a>:</h4>
<p><a href="https://github.com/rust-lang/project-const-generics/issues/7">project-const-generics#7</a> is about structural match for function pointers. The issue is that equality for function pointers is non det at runtime. It is however deterministic at compile time. Considering the utility of allowing function pointers as const params I am still of the opinion that warning for fn ptr comparisions outside of statics/constants and allowing them as const params (but not in <code>match</code> expressions)</p>



<a name="239264691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239264691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239264691">(May 18 2021 at 14:38)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/71415">#71415</a> is about requirements for generic const param types so it's not too relevant for us rn imo</p>



<a name="239265541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239265541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239265541">(May 18 2021 at 14:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239263314">said</a>:</p>
<blockquote>
<p>there's <a href="https://github.com/rust-lang/rust/issues/84391">#84391</a> which brings up some concerns with implicitly making stuff structural match. The concern seems to be that going from a derived <code>PartialEq</code> to a manual one is breaking if it there is a way to get a constant of that type.</p>
</blockquote>
<p>this would be mitigated once users can do <code>unsafe impl StructuralEq for T</code>, i.e. one that trait is stable, right?</p>



<a name="239265719"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239265719" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239265719">(May 18 2021 at 14:44)</a>:</h4>
<p>not sure, because the type probably lost the "structural match property" during that change</p>



<a name="239265900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239265900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239265900">(May 18 2021 at 14:45)</a>:</h4>
<p>e.g. <code>TypeId</code> won't be structurally match after the desired refactoring, so the "bug" is more in that it's currently structural match but shouldn't be</p>



<a name="239265930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239265930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239265930">(May 18 2021 at 14:45)</a>:</h4>
<p>that would be a change in behavior of the <code>PartialEq</code> impl -- so that's like replacing a <code>derive(Clone)</code> with a manual <code>impl Clone</code> that's <em>different</em>. of course that's a breaking change?</p>



<a name="239266028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266028">(May 18 2021 at 14:46)</a>:</h4>
<p>not really, <code>TypeId</code> is fully opaque</p>



<a name="239266085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266085">(May 18 2021 at 14:46)</a>:</h4>
<p>oh so the complaint is that <code>derive(PartialEq)</code> is too implicit in how it also promises StructuralEq?</p>



<a name="239266086"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266086" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266086">(May 18 2021 at 14:46)</a>:</h4>
<p>so as long as the user visible behavior remains the same, i.e. type ids which are equal remain equal</p>



<a name="239266182"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266182" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266182">(May 18 2021 at 14:47)</a>:</h4>
<p>Yeah, also, you can replace <code>derive(PartialEq,Eq)</code> with a structural implementation w/o the implicit StructuralPartialEq,StructuralEq</p>



<a name="239266240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266240">(May 18 2021 at 14:47)</a>:</h4>
<p>(FWIW TypeId might still be StructuralEq after the change -- after all the entire point of that change is to fix TypeId runtime equality tests)</p>



<a name="239266403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266403">(May 18 2021 at 14:48)</a>:</h4>
<p>well, I guess <span class="user-group-mention" data-user-group-id="3805">@project-const-generics</span> <span class="user-group-mention" data-user-group-id="1916">@WG-const-eval</span> structural match meeting time <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span></p>



<a name="239266468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266468">(May 18 2021 at 14:48)</a>:</h4>
<p>(But in this case, yes, the implementation that I seek is not completely structural, as it adds a potential extra strcmp)</p>



<a name="239266480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266480">(May 18 2021 at 14:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239266182">said</a>:</p>
<blockquote>
<p>Yeah, also, you can replace <code>derive(PartialEq,Eq)</code> with a structural implementation w/o the implicit StructuralPartialEq,StructuralEq</p>
</blockquote>
<p>sure, but then (assuming a stable trait) you can also manually <code>unsafe impl StructuralEq</code> for it</p>



<a name="239266611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266611">(May 18 2021 at 14:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239266468">said</a>:</p>
<blockquote>
<p>(But in this case, yes, the implementation that I seek is not completely structural, as it adds a potential extra strcmp)</p>
</blockquote>
<p><code>&amp;str</code> is (or could be) <code>StructuralEq</code> so I dont see the problem with <code>strcmp</code></p>



<a name="239266913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266913">(May 18 2021 at 14:51)</a>:</h4>
<p>True. I can post the particular implementation I had in mind for <code>TypeId</code>, because that may effect that. However, one could argue that references are special cases for structural equality. Though for something like const-generics, that may or may not have issues.</p>



<a name="239266914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266914">(May 18 2021 at 14:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239266403">said</a>:</p>
<blockquote>
<p>well, I guess <span class="user-group-mention" data-user-group-id="3805">@project-const-generics</span> <span class="user-group-mention" data-user-group-id="1916">@WG-const-eval</span> structural match meeting time <span aria-label="sparkles" class="emoji emoji-2728" role="img" title="sparkles">:sparkles:</span></p>
</blockquote>
<p>do we have a problem statement for what we're trying to solve in this meeting?<br>
as you noted I left my thoughts at <a href="https://github.com/rust-lang/rust/issues/74446#issuecomment-841637790">https://github.com/rust-lang/rust/issues/74446#issuecomment-841637790</a>, happy to answer any questions about that</p>



<a name="239266971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239266971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239266971">(May 18 2021 at 14:51)</a>:</h4>
<p>"figure out structural match" :p</p>



<a name="239267058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267058">(May 18 2021 at 14:52)</a>:</h4>
<p>i don't think we have a clear goal here <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="239267061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267061">(May 18 2021 at 14:52)</a>:</h4>
<p>I think we may want to step back and figure out the user visible behaviour first. It seems from the discussion that we aren't even clear on how something fundamental like float should behave</p>



<a name="239267186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267186">(May 18 2021 at 14:53)</a>:</h4>
<p>I think figuring out the underlying structure (heh) helps to determine reasonable user-visible behavior</p>



<a name="239267231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267231">(May 18 2021 at 14:53)</a>:</h4>
<p>so that's what I went for in my post :D</p>



<a name="239267547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267547">(May 18 2021 at 14:55)</a>:</h4>
<blockquote>
<p>STRUCT2: When a value v1 of type T can be converted to a valtree, then T: Eq and for any v2: T, their valtrees are equal if and only if v1 == v2 (in particular if v2 cannot be converted into a valtree, then !(v1 == v2)).</p>
</blockquote>



<a name="239267573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267573">(May 18 2021 at 14:55)</a>:</h4>
<p>Well... the base thing from pattern  matching is that patterns are the reverse of building the value. This opens up questions like "can you deconstruct something with private fields"</p>



<a name="239267619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267619">(May 18 2021 at 14:55)</a>:</h4>
<p>Or can we match NaN</p>



<a name="239267653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267653">(May 18 2021 at 14:55)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219696">XAMPPRocky</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/238868865">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> A “pow wow” is American slang for a meeting. <a href="https://en.wikipedia.org/wiki/Pow_wow">https://en.wikipedia.org/wiki/Pow_wow</a></p>
</blockquote>
<p>you know Ralf, until you asked, I never thought about it, but probably I shouldn't use it. It doesn't seem very respectful. Apologies.</p>



<a name="239267734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267734">(May 18 2021 at 14:56)</a>:</h4>
<p>but I think starting with the problem statement helps, that's kind of user-visible...</p>
<ul>
<li>not all constants can be used as const generic arguments. which subset can we support, and which do we want to make work?</li>
<li>when a constant is used as a pattern, if we want that to interact with exhaustiveness checking (or if we want to match on non-<code>PartialEq</code> constants -- is that a thing?), we again can only support a subset of constants, which subset makes sense?</li>
</ul>



<a name="239267804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267804">(May 18 2021 at 14:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239267619">said</a>:</p>
<blockquote>
<p>Or can we match NaN</p>
</blockquote>
<p>Ouch. The NaN thing is a sticking point as it has many bit-level representations. Are all NaNs equal?</p>



<a name="239267839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267839">(May 18 2021 at 14:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239267573">said</a>:</p>
<blockquote>
<p>Well... the base thing from pattern  matching is that patterns are the reverse of building the value. This opens up questions like "can you deconstruct something with private fields"</p>
</blockquote>
<p>I dont know what you mean by "decosntruct" here -- we're talking about patterns without binders, so this is always just an equality test and of course you can equality test things with private fields</p>



<a name="239267953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267953">(May 18 2021 at 14:57)</a>:</h4>
<p>With "deconstruct" I mean to build a pattern out of an aggregate const</p>



<a name="239267982"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239267982" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239267982">(May 18 2021 at 14:57)</a>:</h4>
<p>that seems like something internal, what's the user-visible part? :D</p>



<a name="239268053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268053">(May 18 2021 at 14:58)</a>:</h4>
<p>We can pattern match things without partialeq impls, just not via constants</p>



<a name="239268085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268085">(May 18 2021 at 14:58)</a>:</h4>
<p>Heh, I forgot that I proposed to use this slot</p>



<a name="239268094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268094">(May 18 2021 at 14:58)</a>:</h4>
<p>So equality is not really the right thing here?</p>



<a name="239268142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268142">(May 18 2021 at 14:58)</a>:</h4>
<p>I'm still catching up from ralf's monster message :)</p>



<a name="239268209"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268209" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268209">(May 18 2021 at 14:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239268094">said</a>:</p>
<blockquote>
<p>So equality is not really the right thing here?</p>
</blockquote>
<p>do you mean "is obviously the right thing"? once we ruled out non-PartialEq then what else would we do?</p>



<a name="239268279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268279">(May 18 2021 at 14:59)</a>:</h4>
<p>(IOW I dont follow your "so", I would have concluded the exact opposite)</p>



<a name="239268294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268294">(May 18 2021 at 14:59)</a>:</h4>
<p>I don't understand what you are asking</p>



<a name="239268430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268430">(May 18 2021 at 15:00)</a>:</h4>
<p>If you have a struct without a partialeq impl, you can still pattern match it directly without constants</p>



<a name="239268434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268434">(May 18 2021 at 15:00)</a>:</h4>
<p>I am saying for a constant <code>C</code>, the pattern <code>C</code> always behaves like the pattern <code>_ if &lt;discriminee&gt; == C</code></p>



<a name="239268465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268465">(May 18 2021 at 15:00)</a>:</h4>
<p>So patterns don't really say anything about equality, right?</p>



<a name="239268484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hameer Abbasi <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268484">(May 18 2021 at 15:00)</a>:</h4>
<p>As long as one can specialise, I think <code>Eq</code> is absolutely the right thing. I think <span class="user-mention" data-user-id="124288">@oli</span> is speaking about how <code>Eq</code> behaves wrt NaN and how it could become impossible to match NaNs.</p>



<a name="239268539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268539">(May 18 2021 at 15:00)</a>:</h4>
<p>Let's ignore nan for now</p>



<a name="239268586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268586">(May 18 2021 at 15:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239268465">said</a>:</p>
<blockquote>
<p>So patterns don't really say anything about equality, right?</p>
</blockquote>
<p>we agree that patterns (in particular those without binders) are closely related to equality, dont we?</p>



<a name="239268635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268635">(May 18 2021 at 15:01)</a>:</h4>
<p>Not necessarily.</p>



<a name="239268638"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268638" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268638">(May 18 2021 at 15:01)</a>:</h4>
<p>they are a kind of equality test, an equivalence relation</p>



<a name="239268673"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268673" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268673">(May 18 2021 at 15:01)</a>:</h4>
<p>Not really</p>



<a name="239268688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268688">(May 18 2021 at 15:01)</a>:</h4>
<p>whether that's the same as <code>==</code> is a different question</p>



<a name="239268695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268695">(May 18 2021 at 15:01)</a>:</h4>
<p>of course they are?</p>



<a name="239268707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268707">(May 18 2021 at 15:01)</a>:</h4>
<p>I think a good goal for this meeting would be to get a high-level view of the operations required and the desired relationships  between them</p>



<a name="239268798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268798">(May 18 2021 at 15:02)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">Foo</span><span class="p">;</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="nb">PartialEq</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Foo</span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">partial_eq</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">bool</span><span class="p">{</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Foo</span><span class="p">{}</span><span class="w"></span>
<span class="k">if</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="n">Foo</span><span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="239268802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268802">(May 18 2021 at 15:02)</a>:</h4>
<p>I think what <span class="user-mention" data-user-id="120791">@RalfJ</span> is saying is that we have two kinds of runtime equaliy test</p>
<ul>
<li>matching against a constant</li>
<li>comparing with <code>==</code></li>
</ul>



<a name="239268821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268821">(May 18 2021 at 15:02)</a>:</h4>
<p>They are about construction and deconstrution to me, often equality means the same thing</p>



<a name="239268904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268904">(May 18 2021 at 15:02)</a>:</h4>
<p>deconstruction is about binding to fields</p>



<a name="239268931"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268931" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268931">(May 18 2021 at 15:02)</a>:</h4>
<p>but we're talking about binder-free patterns here</p>



<a name="239268966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239268966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239268966">(May 18 2021 at 15:03)</a>:</h4>
<p>so I dont think deconstruction is relevant</p>



<a name="239269122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269122">(May 18 2021 at 15:03)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> exactly. we have <code>match x { C =&gt; true, _ =&gt; false }</code> and <code>x == C</code>.</p>



<a name="239269136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269136">(May 18 2021 at 15:03)</a>:</h4>
<p>in particular I dont' think anyone is asserting that the two are necessarily equivalent in behavior</p>



<a name="239269137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269137">(May 18 2021 at 15:03)</a>:</h4>
<p>Isn't lack of binders just a special case?</p>



<a name="239269153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269153">(May 18 2021 at 15:03)</a>:</h4>
<p>Deconstruction without binders is still surely deconstruction?</p>



<a name="239269222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269222">(May 18 2021 at 15:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239269137">said</a>:</p>
<blockquote>
<p>Isn't lack of binders just a special case?</p>
</blockquote>
<p>for constants used as patterns its the only case, isnt it?</p>



<a name="239269344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269344">(May 18 2021 at 15:04)</a>:</h4>
<p>we allow non-StructuralEq patterns on stable today (kind of by accident, but still). so clearly "deconstruction" is not what is going on in general.</p>



<a name="239269392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269392">(May 18 2021 at 15:04)</a>:</h4>
<p>can you give a concrete example thereof?</p>



<a name="239269406"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269406" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269406">(May 18 2021 at 15:05)</a>:</h4>
<p>I guess floats :)</p>



<a name="239269418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269418">(May 18 2021 at 15:05)</a>:</h4>
<p>(potentially?)</p>



<a name="239269470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269470">(May 18 2021 at 15:05)</a>:</h4>
<p>(I'm trying to think how to organize the conversation here a bit)</p>



<a name="239269481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269481">(May 18 2021 at 15:05)</a>:</h4>
<p>no not floats... oli had ane xample somewhere, let me find it...</p>



<a name="239269532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269532">(May 18 2021 at 15:05)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dc3b8eb7eb67cfaa0c0a38c0526a9ed9">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dc3b8eb7eb67cfaa0c0a38c0526a9ed9</a></p>



<a name="239269545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269545">(May 18 2021 at 15:05)</a>:</h4>
<p>do we have a list of "requirements" that pattern matching wants from structural eq and a list of "requirements" that const generics wants?</p>



<a name="239269549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269549">(May 18 2021 at 15:05)</a>:</h4>
<p>The Foo example I showed above wouldn't be <code>StructuralEq</code></p>



<a name="239269685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269685">(May 18 2021 at 15:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239269549">said</a>:</p>
<blockquote>
<p>The Foo example I showed above wouldn't be <code>StructuralEq</code></p>
</blockquote>
<p>thats matching a constructor though, not a constant. I think we are making a difference between those?</p>



<a name="239269767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269767">(May 18 2021 at 15:06)</a>:</h4>
<p>(they are treated very similarly in the compiler internally, but I feel like for this discussion we probably dont want to lump them together)</p>



<a name="239269797"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269797" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269797">(May 18 2021 at 15:07)</a>:</h4>
<p>in particular constructors <em>can</em> have binders when used in patterns (yours just doesnt)</p>



<a name="239269951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269951">(May 18 2021 at 15:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239269532">said</a>:</p>
<blockquote>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dc3b8eb7eb67cfaa0c0a38c0526a9ed9">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=dc3b8eb7eb67cfaa0c0a38c0526a9ed9</a></p>
</blockquote>
<p>that's a good one</p>



<a name="239269963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239269963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239269963">(May 18 2021 at 15:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239269392">said</a>:</p>
<blockquote>
<p>can you give a concrete example thereof?</p>
</blockquote>
<p>so basically the current check stops at references and that's wrong</p>



<a name="239270065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270065">(May 18 2021 at 15:08)</a>:</h4>
<p>ah no it was more complicated</p>



<a name="239270080"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270080" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270080">(May 18 2021 at 15:08)</a>:</h4>
<p>I forgot the details^^</p>



<a name="239270096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270096">(May 18 2021 at 15:08)</a>:</h4>
<p><span class="user-mention silent" data-user-id="326176">Boxy [she/her]</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239269545">said</a>:</p>
<blockquote>
<p>do we have a list of "requirements" that pattern matching wants from structural eq and a list of "requirements" that const generics wants?</p>
</blockquote>
<p>that is a good suggestion, I think, of something to work towards</p>



<a name="239270127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270127">(May 18 2021 at 15:08)</a>:</h4>
<p>but anyway we have a "hole" in our structural-match story</p>



<a name="239270222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270222">(May 18 2021 at 15:09)</a>:</h4>
<p>agreed. I tried that a bit in my text as well.<br>
for pattern matching basically I think we have no requirement at all <em>if</em> we require constants to be <code>PartialEq</code> and ignore them in exhaustiveness checking.</p>



<a name="239270232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270232">(May 18 2021 at 15:09)</a>:</h4>
<p>it seems like there are 3 operations:</p>
<ul>
<li>runtime equality <code>a == b</code></li>
<li>pattern matching against a constant</li>
<li>const generics and equality</li>
</ul>
<p>I think we all basically agree that the first one is not part of this discussion and that it will not necessarily be equivalent to the latter two, but would like there to be some continuum for the latter two?</p>
<p>This is clearly a potential breaking change (though we could do it over an edition if necessary)</p>



<a name="239270297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270297">(May 18 2021 at 15:09)</a>:</h4>
<p>but we currently don't ignore them in exhaustiveness checking, right?</p>



<a name="239270306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270306">(May 18 2021 at 15:09)</a>:</h4>
<p>or at least, sometimes we don't</p>



<a name="239270389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270389">(May 18 2021 at 15:10)</a>:</h4>
<blockquote>
<p>I think we all basically agree that the first one is not part of this discussion and that it will not necessarily be equivalent to the latter two, but would like there to be some continuum for the latter two?</p>
</blockquote>
<p>disagreed. the original StructuralEq proposal, in my interpretation, was all about ensuring that matching against a constant is equivalent to testing equality.</p>



<a name="239270419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270419">(May 18 2021 at 15:10)</a>:</h4>
<p>and in terms of avoiding surprises, that seems like reasonable behavior.</p>



<a name="239270491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270491">(May 18 2021 at 15:10)</a>:</h4>
<p>indeed when matching against contants that cannot be "converted to patterns", that is pretty much the only way we have for compiling a <code>match</code></p>



<a name="239270496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270496">(May 18 2021 at 15:10)</a>:</h4>
<p>OK. I used to feel that way. I've been shifting some.</p>



<a name="239270532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270532">(May 18 2021 at 15:11)</a>:</h4>
<p>so there's literally code in <code>match</code> lowering today that sues PartialEq. thus we definitely have to consider this relationship.</p>



<a name="239270573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270573">(May 18 2021 at 15:11)</a>:</h4>
<p>ah, yes, so this intersects const generics because converting to patterns is not possible unless we do it post-monomorphization</p>



<a name="239270586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270586">(May 18 2021 at 15:11)</a>:</h4>
<p>this also means if we dont have a continuum between PartialEq and match, we get surprising "non-linear" behvaior changes when match lowering switches between one or the other.</p>



<a name="239270739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270739">(May 18 2021 at 15:12)</a>:</h4>
<p>right, so MIR currently lowers to <code>PartialEq</code> because we (falsely) believed that we were limited to cases where this was equivalent</p>



<a name="239270749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270749">(May 18 2021 at 15:12)</a>:</h4>
<p>basically I think we should ensure that just adding <code>unsafe impl StructuralEq for T</code> will never change the behavior of existing code that matches against constants of type <code>T</code></p>



<a name="239270750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270750">(May 18 2021 at 15:12)</a>:</h4>
<blockquote>
<p>ah, yes, so this intersects const generics because converting to patterns is not possible unless we do it post-monomorphization</p>
</blockquote>
<p>The idea here was to always use partialeq for const generics used in patterns</p>



<a name="239270768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270768">(May 18 2021 at 15:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239270573">said</a>:</p>
<blockquote>
<p>ah, yes, so this intersects const generics because converting to patterns is not possible unless we do it post-monomorphization</p>
</blockquote>
<p>I dont follow, what does this have to do with monomorphization?</p>



<a name="239270769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270769">(May 18 2021 at 15:12)</a>:</h4>
<p>Right now we don't allow any generics I think</p>



<a name="239270837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270837">(May 18 2021 at 15:13)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> if there are no generic types involved, are there constants that cannot be converted to patterns?</p>



<a name="239270906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270906">(May 18 2021 at 15:13)</a>:</h4>
<p><code>union</code>s</p>



<a name="239270936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270936">(May 18 2021 at 15:13)</a>:</h4>
<p>interesting</p>



<a name="239270953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270953">(May 18 2021 at 15:13)</a>:</h4>
<p>possibly NaN? possibly raw ptrs / fn ptrs?</p>



<a name="239270958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270958">(May 18 2021 at 15:13)</a>:</h4>
<p>Well, those error even if directly used as a pattern</p>



<a name="239270986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239270986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239270986">(May 18 2021 at 15:14)</a>:</h4>
<p>Can you even match <code>union</code> constants?<br>
If not, should you be able to?</p>



<a name="239271063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271063">(May 18 2021 at 15:14)</a>:</h4>
<p>Unions are a hard error</p>



<a name="239271094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271094">(May 18 2021 at 15:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239270986">said</a>:</p>
<blockquote>
<p>Can you even match <code>union</code> constants?<br>
If not, should you be able to?</p>
</blockquote>
<p>well I'd think you can with oli's trick^^<br>
not sure if unions are ever <code>StructuralEq</code></p>



<a name="239271165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271165">(May 18 2021 at 15:14)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239270953">said</a>:</p>
<blockquote>
<p>possibly NaN? possibly raw ptrs / fn ptrs?</p>
</blockquote>
<p>so, these are kind of "special cases" in my view, but they compile (presently) to the <code>PartialEq</code> impl, and hence NaN != NaN</p>



<a name="239271183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271183">(May 18 2021 at 15:14)</a>:</h4>
<p>Oh... right... the partialeq fallback</p>



<a name="239271229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271229">(May 18 2021 at 15:15)</a>:</h4>
<p>special cases in that they are like constant patterns but they are of atomic types that cannot themselves be further subdivided</p>



<a name="239271300"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271300" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271300">(May 18 2021 at 15:15)</a>:</h4>
<p>unions is an interesting case</p>



<a name="239271301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271301">(May 18 2021 at 15:15)</a>:</h4>
<blockquote>
<p>well I'd think you can with oli's trick^^</p>
</blockquote>
<p>I wasn't able to <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0ae136bff2d56627abbeed9bd8b7eb6e">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=0ae136bff2d56627abbeed9bd8b7eb6e</a></p>



<a name="239271375"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271375" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271375">(May 18 2021 at 15:16)</a>:</h4>
<p>ah, the trick doesnt seem to work for unions?<br>
<a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=80ea280ebd1d6ae6626fb1c61c5f60fb">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=80ea280ebd1d6ae6626fb1c61c5f60fb</a></p>



<a name="239271501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271501">(May 18 2021 at 15:16)</a>:</h4>
<p>Try wrapping it one level deeper in a non structuraleq wrapper type</p>



<a name="239271533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271533">(May 18 2021 at 15:16)</a>:</h4>
<p>...?</p>



<a name="239271536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271536">(May 18 2021 at 15:16)</a>:</h4>
<p>Maybe it won't see the Union then <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>



<a name="239271602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271602">(May 18 2021 at 15:17)</a>:</h4>
<p><a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=62170a5da3cb4e387b6a17f964d44578">the following example prints "other"</a>:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">CFN</span>: <span class="kt">f64</span> <span class="o">=</span><span class="w"> </span><span class="kt">f64</span>::<span class="n">NAN</span><span class="p">;</span><span class="w"></span>
<span class="k">const</span><span class="w"> </span><span class="n">BFN</span>: <span class="kt">f64</span> <span class="o">=</span><span class="w"> </span><span class="kt">f64</span>::<span class="n">NAN</span><span class="p">;</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="n">CFN</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">CFN</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"CFN"</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="n">BFN</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"BFN"</span><span class="p">),</span><span class="w"></span>
<span class="w">        </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="fm">println!</span><span class="p">(</span><span class="s">"Other"</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="239271866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271866">(May 18 2021 at 15:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239271536">said</a>:</p>
<blockquote>
<p>Maybe it won't see the Union then <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span></p>
</blockquote>
<p>it sees even this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">CFN</span>: <span class="kp">&amp;</span><span class="nc">Wrap</span><span class="o">&lt;&amp;</span><span class="n">Wrap</span><span class="o">&lt;</span><span class="n">Bar</span><span class="o">&gt;&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">Wrap</span><span class="p">(</span><span class="o">&amp;</span><span class="n">Wrap</span><span class="p">(</span><span class="n">Bar</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span>: <span class="mi">0</span><span class="w"> </span><span class="p">}));</span><span class="w"></span>
</code></pre></div>



<a name="239271878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271878">(May 18 2021 at 15:18)</a>:</h4>
<p>but anyway I am not sure where this is going?^^</p>



<a name="239271896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271896">(May 18 2021 at 15:18)</a>:</h4>
<p>union in pattern <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4743ba694ed2f00b55d373e0c2aeb61">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=a4743ba694ed2f00b55d373e0c2aeb61</a></p>



<a name="239271958"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239271958" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239271958">(May 18 2021 at 15:19)</a>:</h4>
<p>OK, well, <span class="user-mention" data-user-id="120791">@RalfJ</span> the connection to monomorphization in my mind was somethig like this</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">B</span>: <span class="kt">bool</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">match</span><span class="w"> </span><span class="kc">true</span><span class="w">  </span><span class="p">{</span><span class="w"> </span><span class="n">B</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="o">..</span><span class="p">.,</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Obviously we cant' convert <code>B</code> into anything other than <code>PartialEq</code></p>



<a name="239272006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272006">(May 18 2021 at 15:19)</a>:</h4>
<p>(until we know its value more precisely)</p>



<a name="239272033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272033">(May 18 2021 at 15:19)</a>:</h4>
<p>ah, yes, that too</p>



<a name="239272038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272038">(May 18 2021 at 15:19)</a>:</h4>
<blockquote>
<p>Obviously we cant' </p>
</blockquote>
<p>we can't?  think we should do so</p>



<a name="239272112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272112">(May 18 2021 at 15:20)</a>:</h4>
<p>let me rephrase that: we can't without more MIR constructs</p>



<a name="239272180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272180">(May 18 2021 at 15:20)</a>:</h4>
<p>what we obviously can't do is determine whether that match is exhaustive</p>



<a name="239272189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272189">(May 18 2021 at 15:20)</a>:</h4>
<p>so starting there, I hope we agree that we need a "continuum" between the two ways to compile constants into a pattern (opaque blob with <code>PartialEq</code>, and converting the constant into a proper pattern)</p>



<a name="239272322"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272322" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272322">(May 18 2021 at 15:21)</a>:</h4>
<p>let's elaborate that a bit-- why can't we use <code>ParialEq</code> everywhere</p>



<a name="239272332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272332">(May 18 2021 at 15:21)</a>:</h4>
<ul>
<li>backwards compatibility</li>
</ul>



<a name="239272351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272351">(May 18 2021 at 15:21)</a>:</h4>
<ul>
<li>not as nice, because no exhaustiveness checking</li>
</ul>



<a name="239272510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272510">(May 18 2021 at 15:22)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272332">said</a>:</p>
<blockquote>
<ul>
<li>backwards compatibility</li>
</ul>
</blockquote>
<p>I think we should be fine here -- doesnt oli's example compile to PartialEq so the "bad" cases wouldnt change behavior?</p>



<a name="239272515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272515">(May 18 2021 at 15:22)</a>:</h4>
<p>those two are connected, I think, in that I think the backwards compat concerns are mostly around exhaustiveness checking? or maybe we already do some desugaring of constants and hence there are also cases where the runtime semantics differ?</p>



<a name="239272545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272545">(May 18 2021 at 15:22)</a>:</h4>
<p>I suppose the other question would be: if structural match against constants isn't just PartialEq, what is it? In my mind, w/o references or floats, it's just <code>memcmp_ignore_padding</code>.</p>



<a name="239272654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272654">(May 18 2021 at 15:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272510">said</a>:</p>
<blockquote>
<p>I think we should be fine here -- doesnt oli's example compile to PartialEq so the "bad" cases wouldnt change behavior?</p>
</blockquote>
<p>my belief is that today we do <em>sometimes</em> "unroll" constants into patterns</p>



<a name="239272658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272658">(May 18 2021 at 15:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272545">said</a>:</p>
<blockquote>
<p>I suppose the other question would be: if structural match against constants isn't just PartialEq, what is it? In my mind, w/o references or floats, it's just <code>memcmp_ignore_padding</code>.</p>
</blockquote>
<p>it's "translate/deconstruct constant value to a pattern, match against that pattern".<br>
I think that's equivalent.</p>



<a name="239272678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272678">(May 18 2021 at 15:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272654">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272510">said</a>:</p>
<blockquote>
<p>I think we should be fine here -- doesnt oli's example compile to PartialEq so the "bad" cases wouldnt change behavior?</p>
</blockquote>
<p>my belief is that today we do <em>sometimes</em> "unroll" constants into patterns</p>
</blockquote>
<p>yes we definitely do</p>



<a name="239272731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272731">(May 18 2021 at 15:23)</a>:</h4>
<p>but I guess the check works well enough to ensure we only do that in cases where PartialEq/Eq are derived?</p>



<a name="239272805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272805">(May 18 2021 at 15:24)</a>:</h4>
<p>Also, compiling to a potentially User-defined PartialEq w/ exhaustiveness checking would run into the exact issue that was debated for <a class="stream" data-stream-id="281601" href="/#narrow/stream/281601-project-deref-patterns">#project-deref-patterns</a>, a malicious impl could make assumption of exhaustiveness unsound.</p>



<a name="239272816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272816">(May 18 2021 at 15:24)</a>:</h4>
<p>(do we not do it through <code>&amp;</code> patterns?)</p>



<a name="239272880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272880">(May 18 2021 at 15:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272731">said</a>:</p>
<blockquote>
<p>but I guess the check works well enough to ensure we only do that in cases where PartialEq/Eq are derived?</p>
</blockquote>
<p>I think so... oli's example AFAIK relies on us falling back to the "opaque blob, use PartialEq" path too eagerly without properly checking for StructuralEq</p>



<a name="239272961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272961">(May 18 2021 at 15:25)</a>:</h4>
<blockquote>
<p>(do we not do it through <code>&amp;</code> patterns?)</p>
</blockquote>
<p>Yes</p>



<a name="239272980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239272980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239272980">(May 18 2021 at 15:25)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239272805">said</a>:</p>
<blockquote>
<p>Also, compiling to a potentially User-defined PartialEq w/ exhaustiveness checking would run into the exact issue that was debated for <a class="stream" data-stream-id="281601" href="/#narrow/stream/281601-project-deref-patterns">#project-deref-patterns</a>, a malicious impl could make assumption of exhaustiveness unsound.</p>
</blockquote>
<p>it is definitely true that using PartiaEq without ensuring StructuralEq means we have to ignore the constant for exhaustiveness checking</p>



<a name="239273068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273068">(May 18 2021 at 15:25)</a>:</h4>
<p>StructuralEq, in that view, basically puts the exhaustiveness check correctness obligation on the user and their <code>unsafe impl StrucutralEq</code></p>



<a name="239273099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273099">(May 18 2021 at 15:26)</a>:</h4>
<p>(the trait is currently not unsafe, but if we rely on it like this it has to be)</p>



<a name="239273166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273166">(May 18 2021 at 15:26)</a>:</h4>
<p>Well, that sounds like it would be <code>DerefPure</code> all over again.</p>



<a name="239273194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273194">(May 18 2021 at 15:26)</a>:</h4>
<p>?</p>



<a name="239273231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273231">(May 18 2021 at 15:26)</a>:</h4>
<p>the StructuralEq definition(s) I proposed already take care of this obligation</p>



<a name="239273278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273278">(May 18 2021 at 15:27)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=583e264700a81f30bff5dc742268d2f1">how does this code compile</a>?</p>



<a name="239273332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273332">(May 18 2021 at 15:27)</a>:</h4>
<p>we must be unrolling there, no?</p>



<a name="239273433"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273433" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273433">(May 18 2021 at 15:27)</a>:</h4>
<p><code>reffoo</code> has a <code>switchInt((*_1)) -&gt; [false: bb1, otherwise: bb2]</code></p>



<a name="239273500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273500">(May 18 2021 at 15:28)</a>:</h4>
<p>So <span class="user-mention" data-user-id="120791">@RalfJ</span> I'm coming up a bit slow beacuse I haven't caght up with your messages, but is the outline something like this:</p>
<ul>
<li>there is a way to declare structural equality</li>
<li>if that is not known to be true, we fall back to partial equality ?</li>
</ul>



<a name="239273543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273543">(May 18 2021 at 15:28)</a>:</h4>
<blockquote>
<p>the exhaustiveness check correctness obligation</p>
</blockquote>
<p>we still don't use the <code>PartialEq</code> impl for exhaustiveness checking, do we?</p>



<a name="239273573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273573">(May 18 2021 at 15:28)</a>:</h4>
<p>Yeah, if <code>StructuralEq</code> just skips <code>PartialEq</code> and becomes always a "convert into a pattern and match that", then it would skip the issue of specifying how <code>StructuralEq</code> constrains <code>PartialEq</code></p>



<a name="239273599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273599">(May 18 2021 at 15:28)</a>:</h4>
<blockquote>
<p>if that is not known to be true, we fall back to partial equality ?</p>
</blockquote>
<p>well, usually we fall back to rejecting the pattern. but sometimes we dont and then we fall back to <code>PartialEq</code>.</p>



<a name="239273608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273608">(May 18 2021 at 15:28)</a>:</h4>
<blockquote>
<p>we must be unrolling there, no?</p>
</blockquote>
<p>Yes, we unroll all constants up to where they are not structeq</p>



<a name="239273626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273626">(May 18 2021 at 15:29)</a>:</h4>
<p>exhaustiveness checking only uses val trees (it should imo?)?</p>



<a name="239273653"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273653" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273653">(May 18 2021 at 15:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239273573">said</a>:</p>
<blockquote>
<p>Yeah, if <code>StructuralEq</code> just skips <code>PartialEq</code> and becomes always a "convert into a pattern and match that", then it would skip the issue of specifying how <code>StructuralEq</code> constrains <code>PartialEq</code></p>
</blockquote>
<p>no it wouldnt, since we want to ensure a continuum of behavior between the two ways of compiling patterns</p>



<a name="239273711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273711">(May 18 2021 at 15:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239273626">said</a>:</p>
<blockquote>
<p>exhaustiveness checking only uses val trees (it should imo?)?</p>
</blockquote>
<p>not implemented yet, but that's the plan</p>



<a name="239273735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273735">(May 18 2021 at 15:29)</a>:</h4>
<p>Implemented but not merged</p>



<a name="239273741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273741">(May 18 2021 at 15:29)</a>:</h4>
<p>current valtrees dont support "starts as a tree, then has a blob at some leaf" though :/</p>



<a name="239273885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273885">(May 18 2021 at 15:30)</a>:</h4>
<p>so this could slightly change exhaustiveness checking behavior compared to "we unroll all constants up to where they are not structeq"</p>



<a name="239273920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273920">(May 18 2021 at 15:30)</a>:</h4>
<p>but I hope not really in practice^^</p>



<a name="239273950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239273950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239273950">(May 18 2021 at 15:30)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239273599">said</a>:</p>
<blockquote>
<p>well, usually we fall back to rejecting the pattern. but sometimes we dont and then we fall back to <code>PartialEq</code>.</p>
</blockquote>
<p>what determines the reasons to fall back?</p>



<a name="239274023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274023">(May 18 2021 at 15:31)</a>:</h4>
<p>I'm afraid I am out of my depths here, I carefully avoided the pattern matching code in most of what I do^^</p>



<a name="239274034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274034">(May 18 2021 at 15:31)</a>:</h4>
<p>so for pattern, we could say: while the current type is <code>structural_eq</code>, unroll to a pattern (i.e. with exhaustiveness checking) and once we encounter one type which is not structural eq we stop and use <code>PartialEq</code>. If <code>PartialEq</code> is not implemented for that inner type, error</p>



<a name="239274043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274043">(May 18 2021 at 15:31)</a>:</h4>
<p>This still works with valtree. We create patterns up to the broken thing and then use a mir constant instead of a valtree. All mir constants are compared with partialeq</p>



<a name="239274108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274108">(May 18 2021 at 15:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239274023">said</a>:</p>
<blockquote>
<p>I'm afraid I am out of my depths here, I carefully avoided the pattern matching code in most of what I do^^</p>
</blockquote>
<p>to some extent, this feels like a "design choice" under your proposal, right?</p>



<a name="239274168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274168">(May 18 2021 at 15:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239274034">said</a>:</p>
<blockquote>
<p>so for pattern, we could say: while the current type is <code>structural_eq</code>, unroll to a pattern (i.e. with exhaustiveness checking) and once we encounter one type which is not structural eq we stop and use <code>PartialEq</code>. If <code>PartialEq</code> is not implemented, error</p>
</blockquote>
<p>the thing is, StructuralEq should be a structural property, i.e. it a type is StructuralEq then so are all its constituent types. so having a partial unroll and then transitioning to a blob, IMO should never happen.</p>



<a name="239274171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274171">(May 18 2021 at 15:32)</a>:</h4>
<p>i.e., it's kind of a language design question of what is ergonomic and how confusing it is</p>



<a name="239274256"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274256" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274256">(May 18 2021 at 15:32)</a>:</h4>
<blockquote>
<p>i.e. it a type is StructuralEq then so are all its constituent types.</p>
</blockquote>
<p>yeah, but that's a property which could imo not be worth it?</p>



<a name="239274266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274266">(May 18 2021 at 15:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="124288">oli</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239274043">said</a>:</p>
<blockquote>
<p>This still works with valtree. We create patterns up to the broken thing and then use a mir constant instead of a valtree. All mir constants are compared with partialeq</p>
</blockquote>
<p>I thought the plan was to go constant -&gt; valtree -&gt; pattern? valtrees cannot represent "partially StructuralEq" data so we cant convert it to patterns either</p>



<a name="239274304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274304">(May 18 2021 at 15:33)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239274256">said</a>:</p>
<blockquote>
<blockquote>
<p>i.e. it a type is StructuralEq then so are all its constituent types.</p>
</blockquote>
<p>yeah, but that's a property which could imo not be worth it?</p>
</blockquote>
<p>I think its a fundamental property we need to make any sense of this entire thing^^</p>



<a name="239274387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274387">(May 18 2021 at 15:33)</a>:</h4>
<p>maybe we can pivot briefly to review (for poor me) what ralf's properties of structural equality are?</p>



<a name="239274398"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274398" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274398">(May 18 2021 at 15:33)</a>:</h4>
<p>Structural equality is shallow right now</p>



<a name="239274430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274430">(May 18 2021 at 15:33)</a>:</h4>
<p>I'd like to have the whole set in mind</p>



<a name="239274437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274437">(May 18 2021 at 15:33)</a>:</h4>
<p>yeah and I think tahts bad</p>



<a name="239274444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274444">(May 18 2021 at 15:33)</a>:</h4>
<p>the core of my proposal is</p>
<blockquote>
<p>STRUCT1: Given two values v1, v2 of type T: PartialEq, if both can be converted to a valtree then the valtrees are equal if and only if v1 == v2. Moreover, if v1 can be converted to a valtree and v2 cannot, then !(v1 == v2).</p>
</blockquote>



<a name="239274654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274654">(May 18 2021 at 15:35)</a>:</h4>
<p>(note that the def.n carefully says nothing about valtrees for non-PartialEq types -- so those would be "vacuously structural_eq" -- probably we just want to rule them out by fiat)</p>



<a name="239274749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274749">(May 18 2021 at 15:35)</a>:</h4>
<p>and a valtree is a recursively defined aggregate with certain types at the leaves?</p>



<a name="239274776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274776">(May 18 2021 at 15:35)</a>:</h4>
<p>"certain types" = integer, basically</p>



<a name="239274798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274798">(May 18 2021 at 15:36)</a>:</h4>
<p>but we could imagine adding others</p>



<a name="239274847"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274847" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274847">(May 18 2021 at 15:36)</a>:</h4>
<blockquote>
<p>So e.g. 2 would be a valtree with just a single node carrying a 2; (2, 2) would be a valtree where the root points to two leaf nodes that carry a 2. &amp;2 would be a valtree where the root points to a leaf node that carries a 2. (2,) would be the same valtree as &2; that's okay -- valtrees are meant to capture everything about a value that matters at a high level; comparing valtrees of different types is not very meaningful.</p>
</blockquote>



<a name="239274916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274916">(May 18 2021 at 15:36)</a>:</h4>
<blockquote>
<p>valtrees can represent "partially StructuralEq" data so we cant convert it to patterns either</p>
</blockquote>
<p>I thought the point of valtrees would be that they were entirely <code>StructuralEq</code>, so their values can be encoded for mangling, etc.?</p>



<a name="239274950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239274950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239274950">(May 18 2021 at 15:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239274916">said</a>:</p>
<blockquote>
<blockquote>
<p>valtrees can represent "partially StructuralEq" data so we cant convert it to patterns either</p>
</blockquote>
<p>I thought the point of valtrees would be that they were entirely <code>StructuralEq</code>, so their values can be encoded for mangling, etc.?</p>
</blockquote>
<p>sorry I meant can <em>not</em> represent such data</p>



<a name="239275043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275043">(May 18 2021 at 15:37)</a>:</h4>
<p>so Ralf why do you think it's so important that structural equality is deep, not shallow?</p>



<a name="239275060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275060">(May 18 2021 at 15:37)</a>:</h4>
<blockquote>
<p>I think its a fundamental property we need to make any sense of this entire thing^^</p>
</blockquote>
<p>I think I can make sense of  "For a type to be <code>StructuralEq</code> its <code>partial_eq</code> impl must call <code>partial_eq</code> for all its fields in order"</p>



<a name="239275082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275082">(May 18 2021 at 15:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275043">said</a>:</p>
<blockquote>
<p>so Ralf why do you think it's so important that structural equality is deep, not shallow?</p>
</blockquote>
<p>it follows from my def.n</p>



<a name="239275101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275101">(May 18 2021 at 15:38)</a>:</h4>
<p>valtree construction and comparison is deep</p>



<a name="239275225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275225">(May 18 2021 at 15:38)</a>:</h4>
<p>it definitely follows from your definition :) I'm just trying to understand why you structued the def'n that way</p>



<a name="239275229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275229">(May 18 2021 at 15:38)</a>:</h4>
<p>so if we accept by def.n then I can prove that structural equality is deep, not shallow.^^ and I dont know a useful def.n that would be shallow.</p>



<a name="239275308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275308">(May 18 2021 at 15:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275225">said</a>:</p>
<blockquote>
<p>it definitely follows from your definition :) I'm just trying to understand why you structued the def'n that way</p>
</blockquote>
<p>fair. one big moivation is the "continuum" I keep mentioning.</p>



<a name="239275362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275362">(May 18 2021 at 15:39)</a>:</h4>
<p>the definition is exactly what we need to ensure that compiling patterns either way (when both ways are possible) yields the same behavior.</p>



<a name="239275407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275407">(May 18 2021 at 15:39)</a>:</h4>
<blockquote>
<p>For a type to be StructuralEq its partial_eq impl must call partial_eq for all its fields in order</p>
</blockquote>
<p>I have to admit I really like that def. And I don't see how the continuum is not guaranteed here <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<a name="239275468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275468">(May 18 2021 at 15:40)</a>:</h4>
<p><a href="https://hackmd.io/Qvrj_eOFTkCHZrhJ7f1ItA#Patterns">https://hackmd.io/Qvrj_eOFTkCHZrhJ7f1ItA#Patterns</a> explains this in a bit more detail</p>



<a name="239275518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275518">(May 18 2021 at 15:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275060">said</a>:</p>
<blockquote>
<blockquote>
<p>I think its a fundamental property we need to make any sense of this entire thing^^</p>
</blockquote>
<p>I think I can make sense of  "For a type to be <code>StructuralEq</code> its <code>partial_eq</code> impl must call <code>partial_eq</code> for all its fields in order"</p>
</blockquote>
<p>Are you permitting <code>partial_eq</code> to have a custom impl here?</p>



<a name="239275546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275546">(May 18 2021 at 15:40)</a>:</h4>
<p>the inner ones yeah</p>



<a name="239275568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275568">(May 18 2021 at 15:40)</a>:</h4>
<p>I'm trying to remember if I've seen this hackmd :)</p>



<a name="239275580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275580">(May 18 2021 at 15:40)</a>:</h4>
<p>if so, I've not really read it!</p>



<a name="239275588"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275588" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275588">(May 18 2021 at 15:40)</a>:</h4>
<p>/me reads</p>



<a name="239275625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275625">(May 18 2021 at 15:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275546">said</a>:</p>
<blockquote>
<p>the inner ones yeah</p>
</blockquote>
<p>But then you lose transitivity, reflexivity, etc., which I feel are important for structural equality.</p>



<a name="239275640"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275640" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275640">(May 18 2021 at 15:41)</a>:</h4>
<p>so for const generics we require all constituent types to also be <code>StructuralEq</code></p>



<a name="239275666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275666">(May 18 2021 at 15:41)</a>:</h4>
<p>Ralf's definition is the one that makes most sense to me right now.</p>



<a name="239275715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275715">(May 18 2021 at 15:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275407">said</a>:</p>
<blockquote>
<blockquote>
<p>For a type to be StructuralEq its partial_eq impl must call partial_eq for all its fields in order</p>
</blockquote>
<p>I have to admit I really like that def. And I don't see how the continuum is not guaranteed here <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>
</blockquote>
<p>if those fields have ill-behaved partial_eq impls you still have all the same problems</p>



<a name="239275788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275788">(May 18 2021 at 15:42)</a>:</h4>
<p>basically <em>every</em> <code>derive(PartialEq)</code> newtype of any existing type would be structural eq under this def.n, so I cant see how this def.n guarantees anything useful</p>



<a name="239275928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275928">(May 18 2021 at 15:43)</a>:</h4>
<p>it defines a back compat pattern behavior that seems fairly easy to understand imo</p>



<a name="239275992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239275992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239275992">(May 18 2021 at 15:43)</a>:</h4>
<p>well I certainly dont understand it then^^</p>



<a name="239276040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276040">(May 18 2021 at 15:43)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239275640">said</a>:</p>
<blockquote>
<p>so for const generics we require all constituent types to also be <code>StructuralEq</code></p>
</blockquote>
<p>I think it makes sense for <code>StructuralEq</code> to be a const-generics specific trait, and handle pattern matching separately. We want to be more liberal in what's accepted in pattern matching.</p>



<a name="239276127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276127">(May 18 2021 at 15:44)</a>:</h4>
<blockquote>
<p>basically <em>every</em> <code>derive(PartialEq)</code> newtype of any existing type would be structural eq under this def.n, so I cant see how this def.n guarantees anything useful</p>
</blockquote>
<p>Which would leave it to status quo, would it not?</p>



<a name="239276136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276136">(May 18 2021 at 15:44)</a>:</h4>
<p>Otherwise we're special-casing const-generic <code>StructuralEq</code> anyway.</p>



<a name="239276201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276201">(May 18 2021 at 15:44)</a>:</h4>
<p>also <span class="user-mention" data-user-id="216206">@lcnr</span>  how do you define "constituent types"? what if I write type-erased code like <code>struct I32Ptr(*const ()); // invariant: is a ptr to i32</code>?</p>



<a name="239276270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276270">(May 18 2021 at 15:45)</a>:</h4>
<p>Should raw pointers be compared bytewise, if considered for structuraleq?</p>



<a name="239276280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276280">(May 18 2021 at 15:45)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276127">said</a>:</p>
<blockquote>
<blockquote>
<p>basically <em>every</em> <code>derive(PartialEq)</code> newtype of any existing type would be structural eq under this def.n, so I cant see how this def.n guarantees anything useful</p>
</blockquote>
<p>Which would leave it to status quo, would it not?</p>
</blockquote>
<p>yeah and the status quo is "it's a mess and we dont have a clear idea for what the guarantees are", isnt it?</p>



<a name="239276413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276413">(May 18 2021 at 15:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276040">said</a>:</p>
<blockquote>
<p>I think it makes sense for <code>StructuralEq</code> to be a const-generics specific trait, and handle pattern matching separately. We want to be more liberal in what's accepted in pattern matching.</p>
</blockquote>
<p>hm, I'm afraid of a proliferation of mechanisms here. yes the two require slightly different things in the details, but in broad scopes they are very similar.</p>



<a name="239276484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276484">(May 18 2021 at 15:46)</a>:</h4>
<p>Indeed, and it's comes with a ton of extra promises that people may not realise that they have to keep, or worse, not know whether or not they have to keep them, which is the basis for my issue, <a href="https://github.com/rust-lang/rust/issues/84391">#84391</a>.</p>



<a name="239276491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276491">(May 18 2021 at 15:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276270">said</a>:</p>
<blockquote>
<p>Should raw pointers be compared bytewise, if considered for structuraleq?</p>
</blockquote>
<p>they are not considered for SturcutralEq, at least by me -- they dont have a reasonable notion of equality at compile time</p>



<a name="239276492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276492">(May 18 2021 at 15:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276201">said</a>:</p>
<blockquote>
<p>also <span class="user-mention silent" data-user-id="216206">lcnr</span>  how do you define "constituent types"? what if I write type-erased code like <code>struct I32Ptr(*const ()); // invariant: is a ptr to i32</code>?</p>
</blockquote>
<p>we use partial eq of <code>*const ()</code></p>



<a name="239276512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276512">(May 18 2021 at 15:46)</a>:</h4>
<p>I don't understand yet the envsioned interaction of structural eq and const generics</p>



<a name="239276516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276516">(May 18 2021 at 15:46)</a>:</h4>
<p>but</p>



<a name="239276559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276559">(May 18 2021 at 15:47)</a>:</h4>
<p>I have to go :) I think I get ralf's proposal, I want to podner it a bit, I'll try to catch up on the thread in any case</p>



<a name="239276606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276606">(May 18 2021 at 15:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276512">said</a>:</p>
<blockquote>
<p>I don't understand yet the envsioned interaction of structural eq and const generics</p>
</blockquote>
<p>well basically what I imagined was: <code>&lt;const x: T&gt;</code> is only allowed when <code>T: StructuralEq</code></p>



<a name="239276692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276692">(May 18 2021 at 15:48)</a>:</h4>
<p>I thnk <span class="user-mention" data-user-id="120791">@RalfJ</span> and key point is that you permit (a) matching on any constant and (b) anything with an ill-behaved <code>PartialEq</code> would not be able to (soundly) implement <code>StructuralEq</code>, and hence we would always be conservative about it in exhaustiveness checking</p>



<a name="239276750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276750">(May 18 2021 at 15:48)</a>:</h4>
<blockquote>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276270">said</a>:</p>
<blockquote>
<p>Should raw pointers be compared bytewise, if considered for structuraleq?</p>
</blockquote>
<p>they are not considered for SturcutralEq, at least by me -- they dont have a reasonable notion of equality at compile time</p>
</blockquote>
<p>For something like const generics, you could use the definition C++ has for non-type template parameters, which constrains  the pointers to being either null pointers, or to objects that have linkage (So, pointers to statics)</p>



<a name="239276776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276776">(May 18 2021 at 15:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276606">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276512">said</a>:<br>
well basically what I imagined was: <code>&lt;const x: T&gt;</code> is only allowed when <code>T: StructuralEq</code></p>
</blockquote>
<p>yes, I figured that was roughly it :)</p>



<a name="239276811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276811">(May 18 2021 at 15:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276692">said</a>:</p>
<blockquote>
<p>I thnk <span class="user-mention silent" data-user-id="120791">RalfJ</span> and key point is that you permit (a) matching on any constant and (b) anything with an ill-behaved <code>PartialEq</code> would not be able to (soundly) implement <code>StructuralEq</code>, and hence we would always be conservative about it in exhaustiveness checking</p>
</blockquote>
<p>basically, yes. (we could still restrict which constants we permit matching on though, if we wanted. but it's not required for this scheme to work.)</p>



<a name="239276877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276877">(May 18 2021 at 15:49)</a>:</h4>
<p>I see a lot of appeal to this scheme; I don't yet understand <span class="user-mention" data-user-id="216206">@lcnr</span> why we would want the shallow def'n of structural equality</p>



<a name="239276906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276906">(May 18 2021 at 15:49)</a>:</h4>
<p>maybe you can enumerate some examples it would permit that seem good?</p>



<a name="239276911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276911">(May 18 2021 at 15:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276750">said</a>:</p>
<blockquote>
<p>For something like const generics, you could use the definition C++ has for non-type template parameters, which constrains  the pointers to being either null pointers, or to objects that have linkage (So, pointers to statics)</p>
</blockquote>
<p>yes we could refine things like that. though if the statics have size 0, or if they are <code>extern</code>, they could still have the same address...</p>



<a name="239276921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276921">(May 18 2021 at 15:49)</a>:</h4>
<blockquote>
<p>how do you define "constituent types"</p>
</blockquote>
<p>wrongly <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> i would want to recursively check all "contained" types, where "contained" recursively looking into the types using <code>constituent_types_for_ty</code></p>



<a name="239276948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276948">(May 18 2021 at 15:49)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> this also applies to <code>const X: T</code> in a trait, right?</p>



<a name="239276975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239276975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239276975">(May 18 2021 at 15:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239276948">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> this also applies to <code>const X: T</code> in a trait, right?</p>
</blockquote>
<p>why would it?</p>



<a name="239277073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277073">(May 18 2021 at 15:50)</a>:</h4>
<p>I'm debating :) perhaps it doesn't have to</p>



<a name="239277088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277088">(May 18 2021 at 15:50)</a>:</h4>
<p>I didnt think it would</p>



<a name="239277118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277118">(May 18 2021 at 15:50)</a>:</h4>
<p>equality on const generics matters a lot in the compiler</p>



<a name="239277158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277158">(May 18 2021 at 15:50)</a>:</h4>
<p>equality on values of associatd consts doesnt, I think?</p>



<a name="239277202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277202">(May 18 2021 at 15:51)</a>:</h4>
<p>well, it depends</p>



<a name="239277216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Boxy [she/her] <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277216">(May 18 2021 at 15:51)</a>:</h4>
<p>associated consts can be the value of a const generic so those are the same thing right?</p>



<a name="239277235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277235">(May 18 2021 at 15:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277118">said</a>:</p>
<blockquote>
<p>equality on const generics matters a lot in the compiler</p>
</blockquote>
<p>to elaborate: it becomes part of "equality on types", and that matters</p>



<a name="239277272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277272">(May 18 2021 at 15:51)</a>:</h4>
<p>I supose it would depend on if cg included bounding on traits with specific associated constant values?</p>



<a name="239277278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277278">(May 18 2021 at 15:51)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> can auto traits have super traits? <code>auto trait DeepStructuralEq: StructuralEq {}</code></p>



<a name="239277336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277336">(May 18 2021 at 15:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="326176">Boxy [she/her]</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277216">said</a>:</p>
<blockquote>
<p>associated consts can be the value of a const generic so those are the same thing right?</p>
</blockquote>
<p>if const generics are restricted to StructuralEq types then this is sufficient to cover that case, without also restricting types of associated consts</p>



<a name="239277342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277342">(May 18 2021 at 15:51)</a>:</h4>
<p>Right, I'm thinking that every case where it would become impt to the equality of types implies that the associated constant is a (const) generic parameter of some type, so the restriction applies that way.</p>



<a name="239277423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277423">(May 18 2021 at 15:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277278">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> can auto traits have super traits? <code>auto trait DeepStructuralEq: StructuralEq {}</code></p>
</blockquote>
<p>no, not presently, because of reasons :)</p>



<a name="239277480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277480">(May 18 2021 at 15:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277278">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> can auto traits have super traits? <code>auto trait DeepStructuralEq: StructuralEq {}</code></p>
</blockquote>
<p>IIRC, that either is constrained to other auto traits, or has some <em>flaws</em> because rustc.</p>



<a name="239277489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277489">(May 18 2021 at 15:52)</a>:</h4>
<p>implied bounds + coinductive matching is a recipe for unsoundness</p>



<a name="239277778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277778">(May 18 2021 at 15:54)</a>:</h4>
<p>It could possibly work with <code>unsafe auto trait DeepStructuralEq{}</code> and <code>impl&lt;T: !StructuralEq&gt; !DeepStructuralEq for T{}</code> with negative trait bounds that don't require an explicit <code>impl !StructuralEq for T{}</code></p>



<a name="239277846"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239277846" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239277846">(May 18 2021 at 15:54)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> so what you call "deep structural eq" -- your def.n of structural-eq applied to all constituent types -- is that (supposed to) be equivalent to my definition? it's not obvious to me if they are, could be an interesting thing to figure out.</p>



<a name="239278077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278077">(May 18 2021 at 15:56)</a>:</h4>
<p>certainly you have to be a bit careful here because you need to say <em>something</em> about primitive types being structural eq -- like, <code>i32</code> would be vacuously structural-eq according to your def.n <em>even if</em> we made its PartialEq impl something ridicolous</p>



<a name="239278207"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278207" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278207">(May 18 2021 at 15:56)</a>:</h4>
<p>Wouldn't scalar types by-definition be structural-eq?</p>



<a name="239278230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278230">(May 18 2021 at 15:56)</a>:</h4>
<p>let me write my idea down</p>



<a name="239278303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278303">(May 18 2021 at 15:56)</a>:</h4>
<p>well in my def.n they are structural-eq because they satisfy the property</p>



<a name="239278327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278327">(May 18 2021 at 15:57)</a>:</h4>
<p>no need to make them structural-eq by fiat</p>



<a name="239278474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278474">(May 18 2021 at 15:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277846">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> so what you call "deep structural eq" -- your def.n of structural-eq applied to all constituent types -- is that (supposed to) be equivalent to my definition? it's not obvious to me if they are, could be an interesting thing to figure out.</p>
</blockquote>
<p>it's similar, I am reasoning about types, so all values of your type would have to be able to be constructed as val trees, but my definition isn't completely right</p>



<a name="239278508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278508">(May 18 2021 at 15:57)</a>:</h4>
<p>Yeah, and they do so by definition though.<br>
The valtree of a value of a scalar type <code>x</code> is simply <code>x</code>, is it not?</p>



<a name="239278510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278510">(May 18 2021 at 15:57)</a>:</h4>
<p>writing it in a hackmd rn</p>



<a name="239278607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278607">(May 18 2021 at 15:58)</a>:</h4>
<p>I think <span class="user-mention" data-user-id="216206">@lcnr</span> 's def.n requires talking about them explicitly (and I consider that a weakness -- feels to me like this is a very <em>syntactic</em> definition, whereas what I am looking for is something <em>semantic</em>)</p>



<a name="239278762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278762">(May 18 2021 at 15:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239278508">said</a>:</p>
<blockquote>
<p>Yeah, and they do so by definition though.<br>
The valtree of a value of a scalar type <code>x</code> is simply <code>x</code>, is it not?</p>
</blockquote>
<p>well everything that satisifies the poperty satisfies it by def.n (as in, because STRUCT1 has been defined like that), I dont get that distinction^^</p>



<a name="239278882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278882">(May 18 2021 at 15:59)</a>:</h4>
<p>also "scalar type" makes me uneasy, raw ptrs and references are "scalar types" under some def.ns of that term...</p>



<a name="239278899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239278899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239278899">(May 18 2021 at 15:59)</a>:</h4>
<p>It satisfies the property by definition though, because it's valtree is itself, thus the valtree is equal iff the value itself is equal by Sub=.</p>



<a name="239279049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279049">(May 18 2021 at 16:00)</a>:</h4>
<p>True. I'd then constrain it to integral types.</p>



<a name="239279079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279079">(May 18 2021 at 16:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="257758">Connor Horman</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239278899">said</a>:</p>
<blockquote>
<p>It satisfies the property by definition though, because it's valtree is itself, thus the valtree is equal iff the value itself is equal by Sub=.</p>
</blockquote>
<p>I dont know what you mean by "satisifies the property by definition". after you defined a property that is literally the only way it can ever be satisfied, no? so that just doesnt seem like a meaningful statement to me, is what I say.</p>



<a name="239279166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279166">(May 18 2021 at 16:01)</a>:</h4>
<p>we could show a theorem like</p>
<div class="codehilite"><pre><span></span><code>Lemma scalar_structural: forall (T: scalar_integer_type), is_structural_eq T
</code></pre></div>



<a name="239279212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279212">(May 18 2021 at 16:01)</a>:</h4>
<p>that theorems requires a bit of reasning, but nothing too complicated</p>



<a name="239279328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279328">(May 18 2021 at 16:02)</a>:</h4>
<p>What I'm saying is that the property that <code>(x==y)&lt;=&gt;(valtree(x)==valtree(y))</code> is trivially true, because valtree(x)=x for integer types. Is that not a correct statement?</p>



<a name="239279415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279415">(May 18 2021 at 16:02)</a>:</h4>
<p>I guess thats corretc if you squint your eyes enough^^</p>



<a name="239279457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279457">(May 18 2021 at 16:02)</a>:</h4>
<p><code>valtree(x)</code> has type "valtree" so comparing that with <code>x</code> is an ill-typed statement in my view...</p>



<a name="239279510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279510">(May 18 2021 at 16:02)</a>:</h4>
<p>but I think I get what you mean</p>



<a name="239279523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279523">(May 18 2021 at 16:03)</a>:</h4>
<p>and I agree with that</p>



<a name="239279659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279659">(May 18 2021 at 16:03)</a>:</h4>
<p>I deliberately did not use <code>==</code> on valtrees in my def.n since this is "meta-level equality", whereas the <code>==</code> I am talking about is "Rust-level equality"</p>



<a name="239279777"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239279777" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239279777">(May 18 2021 at 16:04)</a>:</h4>
<p>so your <code>x==y</code> is really <code>rust_code_evaluates_to(quote!{$x == $y}, quote!{true})</code> or so -- there's a lot going on there that's not going on on the valtree side. maybe that's my PL researcher showing through but I think it is important to keep the meta level and the object level clearly separate. ;)</p>



<a name="239280186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239280186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239280186">(May 18 2021 at 16:06)</a>:</h4>
<p>but if we agree on these statements all being a bit fuzzy, then I think we agree :)</p>



<a name="239280745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239280745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Connor Horman <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239280745">(May 18 2021 at 16:08)</a>:</h4>
<p>Yeah I guess they are.</p>



<a name="239280858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239280858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239280858">(May 18 2021 at 16:09)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239278474">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239277846">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> so what you call "deep structural eq" -- your def.n of structural-eq applied to all constituent types -- is that (supposed to) be equivalent to my definition? it's not obvious to me if they are, could be an interesting thing to figure out.</p>
</blockquote>
<p>it's similar, I am reasoning about types, so all values of your type would have to be able to be constructed as val trees, but my definition isn't completely right</p>
</blockquote>
<p>ah, but then how's that related to the shallow definition? I thought one would be defined in terms of the other (that could help me understand the shallow definition better). I'll wait for your writeup. :)</p>



<a name="239281707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239281707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239281707">(May 18 2021 at 16:14)</a>:</h4>
<p>I am also interested in why you think it's worth relaxing the pattern match requirement to something more shallow. you mentioned backcompat I think, but it is really hard to even come up with an example that would be broken by my proposal -- so (unless crater disagrees) I think this is okay breakage. I think a pattern like <code>(0, _blob)</code> is equivalent to <code>_blob</code> in terms of exhaustiveness checking, so weakening from the former to the latter won't break any code... at least I was unable to come up with a counterexample for this.</p>



<a name="239290387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239290387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239290387">(May 18 2021 at 17:10)</a>:</h4>
<p>that's my idea: <a href="https://hackmd.io/-IB2BH1hSWWMQVSfbvVViA">https://hackmd.io/-IB2BH1hSWWMQVSfbvVViA</a></p>



<a name="239290778"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239290778" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239290778">(May 18 2021 at 17:12)</a>:</h4>
<p>this does allow a few things to compile which weren't previously possible</p>



<a name="239291135"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239291135" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239291135">(May 18 2021 at 17:14)</a>:</h4>
<p>soooo <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> i think i messed up something here, because I am somehow missing why "just using" partial eq is bad <span aria-label="sweat" class="emoji emoji-1f613" role="img" title="sweat">:sweat:</span></p>



<a name="239291253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239291253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239291253">(May 18 2021 at 17:15)</a>:</h4>
<p>let me reread some of the existing threads <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="239298921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239298921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239298921">(May 18 2021 at 18:05)</a>:</h4>
<p>i guess it might be interesting to try and force patterns to have that recursive check but always require <code>StructuralMatch</code> instead of just <code>PartialEq</code>. But I do fear that it will break too much code</p>



<a name="239299072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239299072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239299072">(May 18 2021 at 18:06)</a>:</h4>
<p>but i also have to say that i quite like my approach.</p>



<a name="239299147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239299147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239299147">(May 18 2021 at 18:06)</a>:</h4>
<p>which pretty much boils down to: use semantic equality but do check for exhaustiveness if <code>StructuralMatch</code> is implemented</p>



<a name="239470798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239470798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239470798">(May 19 2021 at 18:08)</a>:</h4>
<p>For any desire to handle float values as part of structural equality here, I believe that NaN is comparatively non-problematic compared to a float with <code>0.0</code> or <code>-0.0</code> as its value, because:</p>
<ul>
<li><code>0.0</code> and <code>-0.0</code> are both well-defined values for floats, in all senses you might care about</li>
<li>They are not bit-equal</li>
<li>They are <code>partial_cmp</code> equal</li>
</ul>
<p>They violate float total ordering all on their own, unless you use the <code>total_cmp</code> rules<br>
It's easy to just say "who cares?" about NaN and hack it out of the picture, by comparison, so I don't think fretting over NaN is essential.</p>



<a name="239862411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239862411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239862411">(May 22 2021 at 10:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239299147">said</a>:</p>
<blockquote>
<p>which pretty much boils down to: use semantic equality but do check for exhaustiveness if <code>StructuralMatch</code> is implemented</p>
</blockquote>
<p>this is equivalent with (one variant of) my proposal, for my definition of when it is okay to implement <code>StructuralMatch</code>/<code>StrucutralEq</code> for a type. Now I'll read yours to figure out where the difference is. ;)</p>



<a name="239862492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239862492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239862492">(May 22 2021 at 10:20)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> I dont think "partial_cmp-equal but not bit equal" is a problem. we just have to ensure that their valtrees are equal and they name-mangle to the same thing. which we could achieve by having <code>Float</code> (as in, softfloat) valtree leaves and using an appropriate notion of equality on those.</p>



<a name="239863678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239863678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239863678">(May 22 2021 at 10:40)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> </p>
<div class="codehilite"><pre><span></span><code>/// If wrongly implemented patterns might disagree with
/// `PartialEq`, but that&#39;s not unsound.
</code></pre></div>
<p>if <code>StructuralMatch</code> enables exhaustiveness checking, then wrong impls <em>would</em> be unsound. so I think something is wrong here in your proposal.</p>



<a name="239863725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239863725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239863725">(May 22 2021 at 10:42)</a>:</h4>
<blockquote>
<p>If T: StructuralEq, it is guaranteed that all values of type T can be converted to a val-tree due to the lang item status of StructuralMatch.</p>
</blockquote>
<p>what does the lang item status have to do with this? users are free to implement StructuralMatch, aren't they?</p>



<a name="239863807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239863807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239863807">(May 22 2021 at 10:43)</a>:</h4>
<p>I think other than that this proposal it pretty similar to mine, but it requires 2 notions (StructuralMatch, StructuralEq) where I need only one. the benefit you have from this is exhaustiveness checking for "partially structural" constant -- and I dont think this is actually ever useful: if a constant like <code>(0, foo)</code> can be exhaustiveness-checked only on the first component, that is equivalent to not exhaustiveness-checking it at all.</p>



<a name="239871731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239871731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239871731">(May 22 2021 at 13:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239863678">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> </p>
<div class="codehilite"><pre><span></span><code>/// If wrongly implemented patterns might disagree with
/// `PartialEq`, but that&#39;s not unsound.
</code></pre></div>
<p>if <code>StructuralMatch</code> enables exhaustiveness checking, then wrong impls <em>would</em> be unsound. so I think something is wrong here in your proposal.</p>
</blockquote>
<p><code>StructuralMatch</code> enables exhaustiveness checking by looking at the val tree, not by using partialeq. <code>PartialEq</code> gets completely ignored for exhaustiveness</p>



<a name="239871762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239871762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239871762">(May 22 2021 at 13:07)</a>:</h4>
<blockquote>
<p>users are free to implement StructuralMatch, aren't they?</p>
</blockquote>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="sd">/// Not implementable for types which can't be shallowly converted</span>
<span class="sd">/// back into patterns. So we forbid impls for extern types, float</span>
<span class="sd">/// and pointers.</span>
</code></pre></div>
<p>(this is the responsibility of the compiler, so users are <strong>not</strong> free to implement <code>StructuralMatch</code> for all types</p>



<a name="239871871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239871871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239871871">(May 22 2021 at 13:08)</a>:</h4>
<blockquote>
<p>the benefit you have from this is exhaustiveness checking for "partially structural" constant </p>
</blockquote>
<p>and better perf. Afaik we want <code>match</code> to use patterns as much as possible as it is <em>faster</em></p>



<a name="239873286"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239873286" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239873286">(May 22 2021 at 13:34)</a>:</h4>
<blockquote>
<p>StructuralMatch enables exhaustiveness checking by looking at the val tree, not by using partialeq. PartialEq gets completely ignored for exhaustiveness</p>
</blockquote>
<p>if <code>PartialEq</code> is still used to actually do the check at runtime ("use semantic equality" is what you said), that'd still be unsound</p>



<a name="239873321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239873321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239873321">(May 22 2021 at 13:35)</a>:</h4>
<blockquote>
<p>so users are not free to implement StructuralMatch for all types</p>
</blockquote>
<p>oh. then how do you intent to let users (unsafely) assert to the compiler that their type is sufficiently well-behaved that it can be used in patterns / const generics? I think that's an important feature (and it also ensures that we cannot weasle out of the respinsibility of saying, precisely, what that trait actually guarantees)</p>



<a name="239873336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239873336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239873336">(May 22 2021 at 13:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239871871">said</a>:</p>
<blockquote>
<blockquote>
<p>the benefit you have from this is exhaustiveness checking for "partially structural" constant </p>
</blockquote>
<p>and better perf. Afaik we want <code>match</code> to use patterns as much as possible as it is <em>faster</em></p>
</blockquote>
<p>I'd expect marginal benefits at best</p>



<a name="239890904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239890904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239890904">(May 22 2021 at 18:25)</a>:</h4>
<p>it is only used for types not using <code>StructuralMatch</code>(or types inside of other types not implementing <code>StructuralMatch</code>) for these types we use structural equality. The idea is to use structural equality as much as possible for types implementing <code>StructuralMatch</code> which is checked for exhaustiveness while using <code>PartialEq</code> as a fallback without checking for exhaustiveness</p>



<a name="239890966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239890966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239890966">(May 22 2021 at 18:26)</a>:</h4>
<blockquote>
<p>(unsafely) assert to the compiler that their type is sufficiently well-behaved</p>
</blockquote>
<p>Extern types, floats and pointers never have well-behaved structural equality, do they?</p>



<a name="239937701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239937701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239937701">(May 23 2021 at 09:27)</a>:</h4>
<blockquote>
<p>it is only used for types not using StructuralMatch(or types inside of other types not implementing StructuralMatch) for these types we use structural equality.</p>
</blockquote>
<p>so you mean, for these types we convert to a pattern and ignore <code>PartialEq</code>?<br>
("it" is an unclear reference in your message, and I don't know what it means to "use structural equality".)</p>



<a name="239937723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/239937723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#239937723">(May 23 2021 at 09:27)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/260443-project-const-generics/topic/structural.20equality/near/239890966">said</a>:</p>
<blockquote>
<blockquote>
<p>(unsafely) assert to the compiler that their type is sufficiently well-behaved</p>
</blockquote>
<p>Extern types, floats and pointers never have well-behaved structural equality, do they?</p>
</blockquote>
<p>so what? that's not what I was talking about. I am talking about people that have types without any such thing, but implement their own <code>PartialEq</code> for one reason or another.</p>



<a name="247470919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/247470919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#247470919">(Jul 28 2021 at 15:01)</a>:</h4>
<p>Was there a structural equality meeting planned for today (<a href="https://github.com/rust-lang/lang-team/issues/94">https://github.com/rust-lang/lang-team/issues/94</a>)?</p>



<a name="247471545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/247471545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#247471545">(Jul 28 2021 at 15:06)</a>:</h4>
<p>Oh, I see it's happening in <a href="#narrow/stream/213817-t-lang/topic/structural.20equality.20meeting">https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/structural.20equality.20meeting</a>.</p>



<a name="247491957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/structural%20equality/near/247491957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/structural.20equality.html#247491957">(Jul 28 2021 at 17:44)</a>:</h4>
<p>there was but we canceled it :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>